package com.lc.pianostudent.activity;

import android.os.Bundle;
import android.text.InputFilter;
import android.view.View;
import android.widget.EditText;

import com.lc.pianostudent.BaseApplication;
import com.lc.pianostudent.R;
import com.lc.pianostudent.conn.PostUpdateName;
import com.lc.pianostudent.conn.PostUpdatePerson;
import com.lc.pianostudent.fragment.MineFragment;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

/**
 * Created by Administrator on 2018/6/25.
 */

public class RemarkActivity extends BaseActivity{

    @BoundView(R.id.remark_text) private EditText remark_text;
    //修改昵称
    public PostUpdatePerson postUpdatePerson = new PostUpdatePerson(new AsyCallBack<PostUpdatePerson.PostUpdatePersonInfo>(){

        @Override
        public void onSuccess(String toast, int type, Object o, PostUpdatePerson.PostUpdatePersonInfo postUpdatePersonInfo) throws Exception {

            UtilToast.show(toast);
            finish();

            try {
                ((MineFragment.CallBack)getAppCallBack(MineFragment.class)).onRefresh();
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                ((PersonInfoActivity.CallBack)getAppCallBack(PersonInfoActivity.class)).onRefresh();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onFail(String toast, int type) throws Exception {
            UtilToast.show(toast);
        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_remark);

        setBackTrue();


        initView();
    }

    private void initView(){
        setTitleName("个性签名");
        remark_text.setText(getIntent().getStringExtra("remark"));
        remark_text.setFilters(new InputFilter[]{new InputFilter.LengthFilter(12)});
        setRightName("保存", R.color.textBlack_2e2e2e, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                postUpdatePerson.user_id = BaseApplication.BasePreferences.readUID();
                postUpdatePerson.text = remark_text.getText().toString().trim();
                postUpdatePerson.execute();
            }
        });
    }
}
